package com.hnqcgczy.controller;

import com.hnqcgczy.service.IProductService;
import com.hnqcgczy.service.impl.ProductServiceImpl;
import com.hnqcgczy.vo.TProduct;
import com.hnqcgczy.vo.TProductCategory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/home")
public class HomeServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1 获取服务层商品数据
        List<TProduct> productList=new ArrayList<TProduct>();
        IProductService productService=new ProductServiceImpl();
        productList=productService.getProductList(8);
        //2 将获取的数据存储于session
        req.getSession().setAttribute("productList",productList);

        //商品类目
        List<TProductCategory> categoryList=productService.getCategoryList();
        //商品分类数据存储于session
        req.getSession().setAttribute("categoryList",categoryList);
        //3:重定向到首页
        resp.sendRedirect("/index.jsp");


    }
}
